﻿using AutoMapper;
using BasicInformation.API.Application.Command.LineCommand;
using BasicInformation.Domain;
using BasicInformation.Infrastructure.Interface;
using MediatR;

namespace BasicInformation.API.Application.CommandHandler.LineCommandHandler
{
    public class LineCreateCommandHandler : IRequestHandler<LineCreateCommand, int>
    {
        private readonly IMapper mapper;
        private readonly ILineRepository lineRepository;

        public LineCreateCommandHandler(ILineRepository lineRepository, IMapper mapper)
        {
            this.lineRepository = lineRepository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(LineCreateCommand request, CancellationToken cancellationToken)
        {
            //var info = new Line();
            //info.Id = request.Id;
            //info.LineName = request.LineName;
            //info.Origin = request.Origin;
            //info.OriginAddress = request.OriginAddress;
            //info.EndPoint = request.EndPoint;
            //info.EndPointAddress = request.EndPointAddress;
            //info.OwnerUnit = request.OwnerUnit;
            //info.OwnersName = request.OwnersName;
            //info.OwnersPhone = request.OwnersPhone;
            //info.CreateBy = "张三";
            //info.CreateDate = DateTime.Now;
            //info.UpdateBy = "";
            //info.UpdateDate = null;
            //info.Desc = request.Desc;
            //info.State = false;
            //info.IsDel = false;
            //var res = await lineRepository.Create(info);
            //return res;

            var info = mapper.Map<Line>(request);
            info.CreateBy = "张三";
            info.CreateDate = DateTime.Now;
            info.UpdateBy = "";
            info.UpdateDate = null;
            info.State = null;
            info.IsDel = false;
            return await lineRepository.Create(info);

        }
    }
}
